package com.company.OfferGuide;

import java.util.Arrays;

public class 扑克牌中的顺子 {


    public boolean isStraight(int[] nums) {
        if (nums == null || nums.length == 0) return true;
        int changeNums = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) changeNums++;
        }
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            int j = i + 1;
            if (nums[i] == 0) continue;
            if (nums[j]  == nums[i]) return false;
            else if (nums[j] - nums[i] > 0) {
                changeNums = changeNums - (nums[j] - nums[i] - 1);
                if (changeNums < 0) return false;
            }
        }
        return changeNums >= 0;
    }

}
